﻿using System;
using System.Collections.Generic;
using AMM.Business.Store;
using AMM.Model.Store;

namespace AMM.Forms.Reports.ReportUserControls {
    public partial class SuspenseUnQualifiedReportSearchControl : BaseReportSearchControl {

        public override string ReportName {
            get { return "SuspenseUnQualifiedReport.rdlc"; }
        }

        public override object CrossedThreadOperation() {
            string materialCodeS = this.tbMaterialCode.Text;
            int? vendorValue = Convert.ToInt32(this.ddlVendor.SelectedValueEx);
            if (vendorValue == 0) { vendorValue = null; }

            return this._reportProcessor.GetSuspenseUnQualifiedViewList(materialCodeS, vendorValue);
        }

        public override void ResetSearch() {
            this.tbMaterialCode.Clear();
            this.ddlVendor.SelectedValueEx = null;
        }

        public SuspenseUnQualifiedReportSearchControl() {
            this.InitializeComponent();
        }

        private void BindVendor() {
            VendorSearchModel searchModel = new VendorSearchModel() { IsEnabled = true };
            VendorProcessor vendorProcessor = new VendorProcessor(int.MaxValue);
            List<VendorViewModel> vendorList = vendorProcessor.FetchVendorViewModelList(searchModel);

            this.ddlVendor.DisplayMemberEx = "Code";
            this.ddlVendor.ValueMemberEx = "Key";
            this.ddlVendor.HeightEx = 300;
            this.ddlVendor.WidthEx = 400;
            this.ddlVendor.PageSizeEx = 20;
            this.ddlVendor.DataBind(new VendorViewModel(), x => new { x.Code, x.Name, x.Address }, vendorList);
        }

        private void SuspenseUnQualifiedReportSearchControl_Load(object sender, EventArgs e) {
            this.BindVendor();
        }
    }
}
